//
//  NetMessageCenter.m
//  carcareIOS
//
//  Created by ileo on 16/9/5.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "NetMessageCenter.h"
#import "AIUserInfo.h"
#import "NetEngineServer.h"

@implementation NetMessageCenter

+(void)messageCenterInfoSuccess:(void (^)(NSArray<MessageCenterModel *> *))success fail:(void (^)())fail{
    [[__SELF request:@"/Notice/index" withParams:nil type:REQUEST_POST] requestSuccess:^(id JSON) {
        NSArray *infos = [ValuePropertyObject instanceObjectsWithDictionarys:JSON[@"info"] createObject:^ValuePropertyObject *{
            return [[MessageCenterModel alloc] init];
        }];
        if (success) {
            success(infos);
        }
    } failure:^(id JSON) {
        if (fail) {
            fail();
        }
    }];
}

+(void)messageHadReadWithMessageType:(MessageCenter_Type)type readID:(NSInteger)readID done:(void (^)())done{
    [[__SELF request:@"/Notice/read" withParams:@{@"id":@(readID), @"type":@(type)} type:REQUEST_POST] requestSuccess:^(id JSON) {
        if (done) done();
    } failure:^(id JSON) {
        if (done) done();
    }];
}

+(void)messageLoadWithFirstID:(NSInteger)firID lastID:(NSInteger)lastID messageType:(MessageCenter_Type)type Success:(void (^)(NSArray<MessageModel *> *))success fail:(void (^)())fail{
    [[__SELF request:@"/Notice/list" withParams:@{@"firstId":@(firID), @"lastId":@(lastID), @"type":@(type)} type:REQUEST_POST] requestSuccess:^(id JSON) {
        NSArray *infos = [ValuePropertyObject instanceObjectsWithDictionarys:JSON[@"info"] createObject:^ValuePropertyObject *{
            return [[MessageModel alloc] init];
        }];
        if (success) {
            success(infos);
        }
    } failure:^(id JSON) {
        if (fail) {
            fail();
        }
    }];
}

-(NSDictionary *)requestCommonParams{
    if (![USERINFO.session isNotNil]) {
        return nil;
    }
    return @{@"userid":@(USERINFO.userID),@"session":USERINFO.session};
}

@end
